package util

import (
	"github.com/labstack/echo/v4"
	"net/http"
)

func GetCookie(c echo.Context, key string) string {
	cookie, err := c.Cookie(key)
	if err != nil {
		return ""
	}
	return cookie.Value
}

func SetCookie(c echo.Context, key, value string) {
	cookie := new(http.Cookie)
	cookie.Name = key
	cookie.Value = value
	cookie.Path = "/"
	cookie.HttpOnly = true
	cookie.MaxAge = 86400
	c.SetCookie(cookie)
}

func DelCookie(c echo.Context, key string) {
	cookie := new(http.Cookie)
	cookie.Name = key
	cookie.Path = "/"
	cookie.HttpOnly = true
	cookie.MaxAge = 0
	c.SetCookie(cookie)
}
